export class userStorage {
  // 保存个人用户信息
  static setUser(data: any): void {
    try {
      // localStorage.setItem('userInfo', data);
      // localStorage.setItem('accessToken', data.accessToken, data.expires);
      // localStorage.setItem('refreshToken', data.refreshToken);
    } catch (e) {
      console.error('Error saving user info:', e);
    }
  }

  // 获取个人用户信息
  static getUser() {
    try {
      return localStorage.getItem('userInfo');
    } catch (e) {
      console.error('Error retrieving user info:', e);
      return null;
    }
  }
  // 保存Token
  static setToken(result: API.Result1LoginOutputModel): void {
    try {
      const { accessToken, refreshToken, expires } = result.data || {};
      if (accessToken) localStorage.setItem('accessToken', accessToken);
      if (refreshToken) localStorage.setItem('refreshToken', refreshToken);
      if (expires) localStorage.setItem('expires', expires);
    } catch (e) {
      console.error('Error saving token:', e);
    }
  }

  // 获取用户Token
  static getToken(isAccessToken: boolean = true) {
    if (isAccessToken) {
      return localStorage.getItem('accessToken');
    } else {
      return localStorage.getItem('refreshToken');
    }
  }

  // 移除用户信息
  static removeToken(): void {
    try {
      localStorage.removeItem('userInfo');
      localStorage.removeItem('accessToken');
      localStorage.removeItem('refreshToken');
      localStorage.removeItem('expires');
    } catch (e) {
      console.error('Error deleting user info:', e);
    }
  }
}
